package com.ruiyi.adrobot.web.controller.user;

import com.ruiyi.adrobot.beans.common.ResultMsg;
import com.ruiyi.adrobot.beans.user.User;
import com.ruiyi.adrobot.dao.user.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;

/**
 * Created by tao.zeng on 2017/6/22.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserRepository userRepository;

    @RequestMapping(value = "/toAdd", method = RequestMethod.GET)
    public String toAdd() {
        return "user/add";
    }

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public ResultMsg add(User user) {
        try {
            user.setCreateTime(new Date());
            userRepository.save(user);
        } catch (Exception e) {
            return ResultMsg.error();
        }
        return ResultMsg.success(true);
    }
}
